import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [{
    path: '/',
    redirect: '/Home'
  },
  {
    path: '/Login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/Home',
    name: 'Home',
    component: () => import('../views/Home.vue'),
    redirect: '/Admin', //默认加载页面 Admin.vue
    children: [ //其他需要在Home页面显示的子页面
      {
        path: '/Admin',
        name: 'Admin',
        component: () => import('../views/Admin.vue'),
        meta: {
          role: '超级管理员'
        }
      },
      {
        path: '/Order',
        name: 'Order',
        component: () => import('../views/Order.vue')
      },
      {
        path: '/Total',
        name: 'Total',
        component: () => import('../views/Total.vue')
      },
      { //编辑管理员
        path: '/AdminEdit',
        name: 'AdminEdit',
        component: () => import('../views/AdminEdit.vue')
      },
      {
        path: '/OrderView',
        name: 'OrderView',
        component: () => import('../views/OrderView.vue')
      }, {
        path: '*',
        component: () => import('../views/NotFound.vue')
      }


    ]
  }
]
// 解决重复点击相同路由报错 Error: Avoided redundant navigation to current location:
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
export default router